<template>
    <div class="personal-wrap">
        <p class="role">{{infodata.role}}</p>
        <div class="head">
            <div class="pic-box"><img :src="infodata.headimgurl?infodata.headimgurl:'../assets/images/user.png'" alt="用户头像" /></div>
            <p style="text-align: center;line-height: 30px;padding: 5px 0px 30px;">{{perinfodata.nickname}}</p>
        </div>
        <div class="main">
            <router-link v-for="(item,index) in listdata" :key="index" :to="item.url" v-if="item.hiddens?false:true">
                <mt-cell :title="item.title" is-link class="text-left">
                  <mt-badge type="error" v-if="item.badge">{{item.badge}}</mt-badge>
                </mt-cell>
            </router-link>
            <!-- <mt-button class="signout" size="normal" type="danger" @click.native="handleClick">退出登录</mt-button> -->
        </div>

    </div>
</template>

<style>
    .personal-wrap{padding-bottom: 20px;position: relative;}
    .role{position: absolute;right: 15px;top: 20px;background: #ef4f4f;color: #fff;padding: 2px 3px;border-radius: 5px;font-size: 12px;}
    /* .main{text-align: center;} */
    .pic-box {padding: 30px 0px 0px;text-align: center;}
    .pic-box > img {display: inline-block;width: 30%;border-radius: 50%;box-shadow:0px 0px 10px rgba(0,0,0,.3);}
    .signout{width: 80%;margin: 60px auto 0px;}
    .mint-cell-value.is-link{margin-right: 30px;}
</style>

<script>
import conf from '../config/userconf.js'
export default {
  name: "personal",
  data() {
    return {
      listdata: [
        {
          url: "/coming",        //即将开始考试
          title: "即将开始考试",
        },
        {
          url: "/record",         //查看考试记录
          title: "查看考试记录",
        },
        {
          url: "/examinee",        //需要补考考生
          title: "需要补考考生",
        },
        {
          url: "/addexaminee",        //添加考生
          title: "添加考生"
        },
        {
          url: "/publishnews",        //发布考试通知
          title: "发布考试通知"
        },
        {
          url: "/pendingreview",        //待评卷
          title: "待评卷"
        },
        {
          url: "/historicalreview",        //历史评卷
          title: "历史评卷"
        },
        {
          url: "/set",          //一键练习
          title: "一键练习"
        },
        {
          url: "/newslist",        //消息通知
          title: "消息通知",
        },
        {
          url: "/transfer",        //单位属性迁移
          title: "单位属性迁移"
        }
      ],
      infodata: {},  //信息
      perinfodata: {},  
    };
  },
  methods: {
      init(data=null){
        console.log(this.$route.query.t);
        if(this.$route.query.token){
          window.localStorage.Token = this.$route.query.token;
        }
        // window.localStorage.Token = '3ee27e7fbc42240bc77bc74c4f89df3dd228cd61';   //科主任
        // window.localStorage.Token = '3ee27e7fbc42240bc77bc74c4f89df3dd228cd62';  //科秘书
        window.localStorage.Token = '3ee27e7fbc42240bc77bc74c4f89df3dd228cd63';    //考生

        //首次进入获取url的token请求获取对应身份
        conf.exams.getRole(data,(state,res)=>{
          if (state == 'success'&&res.data.status == 1){
              // console.log(res.data);
              window.localStorage.userRole = res.data.other.role;   //用户身份   8 科主任   9科秘书   10 考生
              if(res.data.other.role == 10){  //考生

                  conf.exams.userinfo1(data,(state,res)=>{
                    if (state == 'success'&&res.data.status == 1){
                        // console.log(res.data);

                        this.infodata = res.data.other.info;
                        this.listdata[0].badge = res.data.other.info.coming;
                        // this.listdata[8].badge = res.data.other.info.notice;

                        this.listdata[2].hiddens = true;
                        this.listdata[3].hiddens = true;
                        this.listdata[4].hiddens = true;
                        this.listdata[5].hiddens = true;
                        this.listdata[6].hiddens = true;
                        
                    }else if(state == 'success'&&res.data.status != 1){
                        this.$toast(res.data.message);
                    }
                  })

              }else if(res.data.other.role == 9){  //科秘书

                  conf.exams.userinfo2(data,(state,res)=>{
                    if (state == 'success'&&res.data.status == 1){
                        // console.log(res.data);

                        this.infodata = res.data.other.info;
                        this.listdata[0].badge = res.data.other.info.coming;
                        // this.listdata[8].badge = res.data.other.info.notice;
                        this.listdata[2].badge = res.data.other.info.again_exam;

                        this.listdata[3].hiddens = true;
                        this.listdata[5].hiddens = true;
                        this.listdata[6].hiddens = true;
                        this.listdata[7].hiddens = true;
                        
                    }else if(state == 'success'&&res.data.status != 1){
                        this.$toast(res.data.message);
                    }
                  })

              }else if(res.data.other.role == 8){  //科主任

                  conf.exams.userinfo3(data,(state,res)=>{
                    if (state == 'success'&&res.data.status == 1){
                        // console.log(res.data);

                        this.infodata = res.data.other.info;
                        this.listdata[0].badge = res.data.other.info.coming;
                        this.listdata[5].badge = res.data.other.info.score;
                        // this.listdata[8].badge = res.data.other.info.notice;

                        this.listdata[2].hiddens = true;
                        this.listdata[3].hiddens = true;
                        this.listdata[4].hiddens = true;
                        this.listdata[7].hiddens = true;
                        
                    }else if(state == 'success'&&res.data.status != 1){
                        this.$toast(res.data.message);
                    }
                  })

              }


              
          }else if(state == 'success'&&res.data.status != 1){
              this.$toast(res.data.message);
          }
        })

        //获取用户基本信息
        conf.exams.userinfo(data,(state,res)=>{
          if (state == 'success'&&res.data.status == 1){
              // console.log(res.data);
              this.perinfodata = res.data.other.info;
              window.localStorage.orgname = res.data.other.info.orgname;  //
              
          }else if(state == 'success'&&res.data.status != 1){
              this.$toast(res.data.message);
          }
        })
        
      },
  },
  mounted() {
    this.init();
    document.title = "个人中心";
  }
};
</script>
